 package com.oanda.blackberry.view;
 
 import net.rim.device.api.system.Bitmap;
 import net.rim.device.api.system.Display;
 import net.rim.device.api.system.EncodedImage;
 import net.rim.device.api.ui.Font;
 import net.rim.device.api.ui.Graphics;
 import net.rim.device.api.ui.component.ListField;
 import net.rim.device.api.ui.component.ListFieldCallback;
 
 public abstract class AbstractListFieldCallBack
   implements ListFieldCallback
 {
   protected Bitmap bg = null;
   protected Bitmap bgSelected = null;
   protected static final int PADDING = 2;
   Font normal14 = Font.getDefault().derive(0, 14);
 
   Font normal = Font.getDefault().derive(0, 18);
   Font bigger = Font.getDefault().derive(1, 28);
   Font small = Font.getDefault().derive(0, 12);
 
   Font plain22 = Font.getDefault().derive(1, 22);
   Font plain24 = Font.getDefault().derive(1, 24);
   Font plain28 = Font.getDefault().derive(1, 28);
 
   int horizontalPadding = 2;
   int verticalPadding = 2;
 
   protected void drawImage(Graphics graphics, int x, int y, int height, EncodedImage image)
   {
     int imageWidth = image.getWidth();
     int imageHeight = image.getHeight();
     int imageTop = y + (height - imageHeight) / 2;
     int imageLeft = x + (height - imageWidth) / 2;
 
     graphics.drawImage(imageLeft, imageTop, imageWidth, imageHeight, image, 0, 0, 0);
   }
 
   protected void drawImage(Graphics graphics, int x, int y, int height, Bitmap image)
   {
     int imageWidth = image.getWidth();
     int imageHeight = image.getHeight();
     int imageTop = y + (height - imageHeight) / 2;
     int imageLeft = x + (height - imageWidth) / 2;
 
     graphics.drawBitmap(imageLeft, imageTop, imageWidth, imageHeight, image, 0, 0);
   }
 
   protected void drawBackground(Graphics graphics, int x, int y, int width, int height, boolean selected) {
     Bitmap bitmap = null;
     if (selected)
       bitmap = this.bgSelected;
     else {
       bitmap = this.bg;
     }
 
     if (bitmap == null) return;
 
     if (bitmap.getWidth() >= width) {
       graphics.drawBitmap(x, y, width, height, bitmap, 0, 0);
     } else {
       int imageWidth = bitmap.getWidth();
       while (width > -2) {
         graphics.drawBitmap(x - 1, y - 1, width + 2, height + 1, bitmap, 0, 0);
         width -= imageWidth;
         x += imageWidth - 2;
       }
     }
   }
 
   protected void drawBorder(Graphics graphics, int x, int y, int width, int height)
   {
     graphics.setColor(8421504);
     graphics.drawLine(x, y - 1, x + width, y - 1);
     graphics.drawLine(x, y + height - 1, x + width, y + height - 1);
   }
 
   protected int drawText(Graphics graphics, int x, int y, int width, int height, String text, boolean selected, int state)
   {
     int fontHeight = 3 * height / 5 - 4;
     graphics.setFont(Font.getDefault().derive(1, fontHeight));
 
     if (selected) {
       graphics.setColor(0);
     }
     else if (state == 1)
       graphics.setColor(16711680);
     else if (state == 2)
       graphics.setColor(32768);
     else {
       graphics.setColor(8421504);
     }
 
     if (text != null) {
       return graphics.drawText(text, x + 2 + 3, y + 2 + 2 + fontHeight / 2, 118, width - x - 4);
     }
 
     return 0;
   }
 
   public int indexOfList(ListField listField, String prefix, int start) {
     return listField.getSelectedIndex();
   }
 
   public int getPreferredWidth(ListField listField) {
     return Display.getWidth();
   }
 
   public void setBg(Bitmap bg) {
     this.bg = bg;
   }
 
   public void setBgSelected(Bitmap bgSelected) {
     this.bgSelected = bgSelected;
   }
 
   public abstract Object get(ListField paramListField, int paramInt);
 
   public abstract void drawListRow(ListField paramListField, Graphics paramGraphics, int paramInt1, int paramInt2, int paramInt3);
}

